package cn.hx.controller;

import cn.hx.entity.Attendance;
import cn.hx.service.AttendanceService;
import cn.hx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class AttendanceController {

    @Autowired
    UserService userService;
    @Autowired
    private AttendanceService attendanceService;

    @GetMapping("searchAttendance")
    public String getSearchAttendance(Model model){
        model.addAttribute("attendances",attendanceService.findAll());
        return "searchAttendance";
    }

    @GetMapping("createAttendance")
    public ModelAndView getCreateAttendance(){
        ModelAndView modelAndView = new ModelAndView("createAttendance");
        modelAndView.addObject("users",userService.selectAll());
        return modelAndView;
    }
//    新增员工信息
    @PostMapping("saveAttendance")
    public String postAttendance(Attendance attendance){
        System.out.println(attendance);
        attendanceService.insert(attendance);
        return "redirect:/searchAttendance";
    }


}
